package com.atguigu.java2;

import com.atguigu.java1.Employee;
import com.atguigu.java1.EmployeeDate;
import org.junit.Test;

import java.util.List;
import java.util.stream.Stream;

/**
 * 测试Stream 的中间操作
 *
 * @author shkstart
 * @create 2021-03-06 10:27
 */
public class StreamAPITest1 {
    @Test
    public void tes00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000t1() {
        List<Employee> list = EmployeeDate.getEmployees();
//         filter(Predicate p)-接收 lambda,从流中排除某些元素。
        Stream<Employee> stream = list.stream();
        stream.filter(e -> e.getSalary() > 122).forEach(System.out::println);

//         limit(n)-截断流，使其元素不超过给定数量

        list.stream().filter(e -> e.getSalary() > 120).limit(2).forEach(System.out::println);
        System.out.println("*******************");
//         skip(n)-跳过元素，返回一个扔掉了前n个元素的流。若流中元素不足n个，则返回一个空流，与limit互补
        list.stream().skip(3).forEach(System.out::println);


//         distinct-筛选，通过流所生成元素的hashCode()和equals()去除重复元素
        list.add(new Employee(1005, "小大", 12, 1234));
        list.add(new Employee(1005, "小大", 12, 1234));
        list.add(new Employee(1005, "小大", 12, 1234));

        list.stream().distinct().forEach(System.out::println);

    }

    //映射
    @Test
    public void test2() {


    }
}
